package iotwisp.school.system.service;

import iotwisp.school.system.qo.ImageQO;
import iotwisp.base.orm.BaseDao;
import iotwisp.school.system.command.BindImageToBizSCmd;
import iotwisp.school.system.command.CreateImageSCmd;
import org.hibernate.Criteria;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import iotwisp.school.system.entity.Image;

@Service
@Transactional
public class ImageService extends BaseDao<Image, ImageQO> {

	public Image createImage(CreateImageSCmd cmd) {

		// 新建图片信息
		Image image = new Image();
		image.create(cmd);
		// 保存图片信息
		save(image);

		return image;
	}

	public void bindImageToBiz(BindImageToBizSCmd cmd) {
		Image image = get(cmd.getImageId());
		image.bindToBiz(cmd);
		update(image);
	}

	@Override
	protected Criteria buildCriteria(Criteria criteria, ImageQO qo) {
		return criteria;
	}

	@Override
	protected Class<Image> getEntityClass() {
		return Image.class;
	}

}
